/*
 * record.cc
 *
 *  Created on: Dec 19, 2014
 *      Author: root
 */
/******************************************************************************************************************/
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "record.h"
/******************************************************************************************************************/
Record::Record(int num_of_attr) {
	this->num_of_attr = num_of_attr;
}
void Record::ToString() {
	char info[128] = { 0 };
//		sprintf(info, "%f, %f", this->attr[CS_PKTS], this->attr[SC_PKTS], this->attr[CS_BYTES]);
	for (int i = 0; i < num_of_attr; i++) {
		sprintf(info + strlen(info), "%f, ", this->attr[i]);
	}
	sprintf(info + strlen(info), "%s", this->label);
	printf("%s\n", info);

}
double Record::GetLen() {
	double tmp = 0.0;
	for (int i = 0; i < num_of_attr; i++) {
		tmp += this->attr[i] * this->attr[i];
	}
	return sqrt(tmp);
}
void Record::Standardize() {
}
void Record::SetLabel(const char* label) {
	strcpy(this->label, label);
}
double Record::GetEuDis(Record* r) {
	double tmp = 0.0;
	for (int i = 0; i < num_of_attr; i++) {
		tmp += (this->attr[i] - r->attr[i]) * (this->attr[i] - r->attr[i]);
	}
	return sqrt(tmp);
}
double Record::GetCosDis(Record* r) {
	double tmp = 0.0;
	for (int i = 0; i < num_of_attr; i++) {
		tmp += this->attr[i] * r->attr[i];
	}
	return tmp / (this->GetLen() * r->GetLen());
}
/******************************************************************************************************************/
